package com.ericsson.mhealth.server.config.providers;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.log4j.Logger;

import com.ericsson.mhealth.gvf.GVFConnectionManager;
import com.ericsson.mhealth.gvf.GVFDefaultConnectionManager;
import com.ericsson.mhealth.gvf.GVFManager;
import com.ericsson.mhealth.server.config.annotations.InjectLogger;
import com.google.inject.Provider;

public class SmartGVFManagerProvider implements Provider<GVFManager> {

	@InjectLogger Logger logger;
	
	@Override
	public GVFManager get() {
		InetAddress technicalNodeIP = null;
		int technicalNodeTCP=10000;
		
		try {
			technicalNodeIP = InetAddress.getAllByName("194.152.253.84")[0];
		}
		catch (UnknownHostException e) {
			try {
				technicalNodeIP = InetAddress.getAllByName("dxmh1")[0];

			} catch (UnknownHostException e1) {
				logger.error("Unable to connect to TN dxmh1 or 194.152.253.84");
			}
		}
		GVFConnectionManager gvfConnectionManager = new GVFDefaultConnectionManager(technicalNodeIP, technicalNodeTCP);
		return GVFManager.newInstance(gvfConnectionManager);
	}

}
